<?php

use yii\db\Query;
use console\db\channels\TransferTableMigration;

/**
 * 用户信息表转移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300000_000005_t_user_meta extends TransferTableMigration {

    /**
     * 自定义查询
     * @inheritdoc
     */
    public function buildQuery() {
        $columns = [
            'uid',
            'username',
            'mobile',
            'portrait',
            'regip',
        ];
        return $query = (new Query())->from('{{%member}}')->select($columns);
    }

    /**
     * @see TransferTableMigration
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'user_meta' => 'member',
            ],
            'columns' => [
                'id' => 'uid',
                'nickname' => 'username',
                'temp_mobile' => 'mobile',
                'avatar' => function($data) {
                    if ($data['portrait']) {
                        return '/uploads/' . ltrim($data['portrait'], '/');
                    }
                    return '';
                },
                'temp_ip' => 'regip',
            ]
        ];
    }

}
